package cn.demoncat.util.pay.yeepay.entity;

import cn.demoncat.util.lang.constant.StatusConstant;
import cn.demoncat.util.pay.yeepay.constant.TradeOrderStatus;
import cn.demoncat.util.pay.yeepay.constant.YeepayConstant;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 响应参数-交易订单查询
 *
 * @author 延晓磊
 * @since 2020年10月19日
 */
public class TradeOrderQueryResult extends YeepayResult{

    // 订单编号
    private String orderId;
    // 易宝收款订单号
    private String uniqueOrderNo;
    // 状态：TradeOrderStatus.name()
    private String status;
    // 订单金额（元）
    private BigDecimal orderAmount;
    // 支付金额（元）
    private BigDecimal payAmount;
    // 商户手续费（元）
    private BigDecimal merchantFee;
    // 支付成功时间
    private LocalDateTime paySuccessDate;
    /**
     * 是否分账
     * 1：分账-分账后D1转账到目标商户的银行卡
     * 0：不分账-支付后D1转账到平台银行卡
     */
    private String fundProcessType;

    /**
     * 构建结果
     *
     * @param other 请求结果
     * @return
     */
    public static TradeOrderQueryResult build(YeepayResult other){
        return build(other.check(null,null,"OPR00000"), TradeOrderQueryResult.class);
    }

    /**
     * 查询状态
     */
    public TradeOrderStatus status() {
        if (this.status != null) {
            return TradeOrderStatus.valueOf(this.status);
        }
        return null;
    }

    /**
     * 设置是否分账
     *
     * @param  fundProcessType 分账"DELAY_SETTLE"，不分账""
     */
    public void setFundProcessType(String fundProcessType) {
        if (StatusConstant.Common.isYes(fundProcessType) || StatusConstant.Common.isNo(fundProcessType)) {
            this.fundProcessType = fundProcessType;
        }else{
            this.fundProcessType = YeepayConstant.FUND_PROCESS.equals(fundProcessType) ? StatusConstant.Common.YES : StatusConstant.Common.NO;
        }
    }

    public String getOrderId() {
        return orderId;
    }

    public void setOrderId(String orderId) {
        this.orderId = orderId;
    }

    public String getUniqueOrderNo() {
        return uniqueOrderNo;
    }

    public void setUniqueOrderNo(String uniqueOrderNo) {
        this.uniqueOrderNo = uniqueOrderNo;
    }

    public BigDecimal getOrderAmount() {
        return orderAmount;
    }

    public void setOrderAmount(BigDecimal orderAmount) {
        this.orderAmount = orderAmount;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public BigDecimal getPayAmount() {
        return payAmount;
    }

    public void setPayAmount(BigDecimal payAmount) {
        this.payAmount = payAmount;
    }

    public BigDecimal getMerchantFee() {
        return merchantFee;
    }

    public void setMerchantFee(BigDecimal merchantFee) {
        this.merchantFee = merchantFee;
    }

    public LocalDateTime getPaySuccessDate() {
        return paySuccessDate;
    }

    public void setPaySuccessDate(LocalDateTime paySuccessDate) {
        this.paySuccessDate = paySuccessDate;
    }

    public String getFundProcessType() {
        return fundProcessType;
    }

}
